package tichu_project252.Round;

import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import tichu_project252.CardClasses.Card;
import tichu_project252.CardClasses.Phoenix;
import tichu_project252.Table;

public class TurnType {

    /**
     *
     * <p><b>Constructor: </b> TurnType()</p>
     *
     * <p><b>Precondition: </b> There is a model </p> <p><b>Postcondition: </b>
     * </p>
     *
     */
    public TurnType() {
    }

    public static LinkedList<Integer> removeDuplicates(LinkedList<Integer> l) {
        //a set cannot have duplicates, but won't work for cards as is
        HashSet hs = new HashSet();
        //put all intReprs of the cards we want to check in the set
        hs.addAll(l);
        //clear the list and add the set elements back to the list
        l.clear();
        l.addAll(hs);
        //and return it, now we have removed the duplicates
        return l;
    }

    static class CardComparator implements Comparator {

        public int compare(Object o1, Object o2) {
            Card c1 = (Card) o1;
            Card c2 = (Card) o2;

            if (c1.getintRepr() > c2.getintRepr()) {
                return 1;
            } else if (c1.getintRepr() == c2.getintRepr()) {
                return 0;
            } else {
                return -1;
            }
        }
    }

    protected static boolean hasPhoenix(LinkedList<Card> hand) {
        for (int i = 0; i < hand.size(); i++) {
            if (hand.get(i) instanceof Phoenix) {
                return true;
            }
        }
        return false;
    }

    protected static void setPhoenix(LinkedList<Card> hand) {
        int i;
        //find its location
        for (i = 0; i < hand.size(); i++) {
            if ("Phoenix".equals(hand.get(i).getstringRepr())) {
                //and set its value equal to one of the other cards
                if (i == 0) {
                    //if phoenix is the first card, then choose the next one
                    hand.get(i).setintRepr(hand.get(i + 1).getintRepr());
                } else {
                    //otherwise choose the one before it
                    hand.get(i).setintRepr(hand.get(i - 1).getintRepr());
                }
            }
        }

    }

 
}
